package net.ge.mosq.web.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.ge.mosq.Constants;
import net.ge.mosq.jdo.entity.AccountItem;
import net.ge.mosq.service.ServiceFactory;

@SuppressWarnings("serial")
public class AccountServlet extends BaseServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		AccountItem ai = new AccountItem();
		ai.setName(request.getParameter(Constants.ACCOUNT_NAME));
		ai.setCode(request.getParameter(Constants.ACCOUNT_CODE));
		ai.setDescription(request.getParameter(Constants.ACCOUNT_DESCRIPTION));
		ai.setCurrency(request.getParameter(Constants.ACCOUNT_CURRENCY));
		ai.setColor(request.getParameter(Constants.ACCOUNT_COLOR));
		ai.setNotes(request.getParameter(Constants.ACCOUNT_NOTES));
		ai.setPlaceholder(request.getParameter(Constants.ACCOUNT_PLACEHOLDER));
		ai.setType(request.getParameter(Constants.ACCOUNT_TYPE));
		ai.setParentId(Long.parseLong(request
				.getParameter(Constants.ACCOUNT_PARENTID)));
		ai.setEmail("common");
		ServiceFactory.getAccountService().createAnAccount(ai);
		response.sendRedirect("/main.jsp");
	}
}
